﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

using Core.Settings;

namespace RandomNetworksExplorer
{
    public partial class Remove250 : Form
    {
        public Remove250()
        {
            InitializeComponent();
        }

        private void Remove250_Load(object sender, EventArgs e)
        {
            sourceResultTxt.Text = ExplorerSettings.StorageDirectory;
        }

        private void sourceBrowse_Click(object sender, EventArgs e)
        {
            if (sourceBrowserDlg.ShowDialog() == DialogResult.OK)
            {
                sourceResultTxt.Text = sourceBrowserDlg.SelectedPath;
            }
        }

        private void convert_Click(object sender, EventArgs e)
        {
            convert.Enabled = false;

            string[] files = Directory.GetFiles(sourceResultTxt.Text);
            int[] result = new int[files.Length];
            for (int k = 0; k < files.Length; ++k)
            {
                List<string> output = new List<string>();
                using (StreamReader streamreader = new StreamReader(files[k], System.Text.Encoding.Default))
                {
                    string[] saparators = { " ", ",", ";" };
                    string contents;
                    while ((contents = streamreader.ReadLine()) != null)
                    {
                        string[] split = contents.Split(saparators, StringSplitOptions.None);
                        int i = Convert.ToInt32(split[0]), j = Convert.ToInt32(split[1]);
                        if (i < 250 || j < 250)
                            continue;
                        else
                        {
                            i -= 250;
                            j -= 250;
                            output.Add(i.ToString() + "," + j.ToString());
                        }
                    }

                    using (System.IO.StreamWriter file = new System.IO.StreamWriter(files[k] + "_out.txt"))
                    {
                        foreach (string s in output)
                            file.WriteLine(s);
                    }
                }
            }

            MessageBox.Show("Successfully converted from.");
            convert.Enabled = true;
        }

        
    }
}
